<?php
namespace app\common\service;

use app\common\logic\CartLogic;
use app\common\logic\GoodsLogic;
use think\Page;
use app\common\logic\wechat\WechatUtil;
use think\facade\Db;

class GetFregihtInfo extends Base {
    static $AUTH_CHECK = false; //默认必须登录
    public function index(){

        $goods_id = input('goods_id');//143
        $region_id = input('region_id');//28242
        $goods_num = input('goods_num')?:1;
        $item_id = 0;

        $goods = Db::name('goods')->where('goods_id',$goods_id)->find();

        $freightLogic = logic('FreightLogic');
        $freightLogic->setGoodsModel($goods);
        //规格
        if($item_id){
            $specgoods = Db::name('spec_goods_price')->where('item_id',$item_id)->find();
            $freightLogic->setSpecGoodsModel($specgoods);
        }
        $freightLogic->setRegionId($region_id);
        $freightLogic->setGoodsNum($goods_num);
        $isShipping = $freightLogic->checkShipping();
        if($isShipping){
            $freightLogic->doCalculation();
            $freight = $freightLogic->getFreight();
            $dispatching_data = ['status'=>true,'msg'=>'可配送','data'=>['freight'=>$freight]];
        }else{
            $dispatching_data = ['status'=>false,'msg'=>'该地区不支持配送','data'=>''];
        }
        return $dispatching_data;
    }

       
}